package com.java2405.first.luoyang_management.effective_population_management.controller;


import com.java2405.first.luoyang_management.effective_population_management.entity.FpOtherInformation;
import com.java2405.first.luoyang_management.effective_population_management.service.impl.FpOtherInformationServiceImpl;
import com.java2405.first.luoyang_management.entity.User;
import com.java2405.first.luoyang_management.jwt.utils.JwtUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * <fp>
 * 流动人口信息表 前端控制器
 * </fp>
 *
 * @author zzh
 * @since 2025-03-14
 */
@RestController
@RequestMapping("/fp")
public class FpOtherInformationController {

    @Resource
    FpOtherInformationServiceImpl fpOtherInformationService;
    @GetMapping("/login")
    public Map<String,Object> login(String username, String password) {
        Map<String, Object> map = new HashMap<>();
        try{
            Map<String,String> payload = new HashMap<>();

            payload.put("id","1");
            payload.put("name",username);
            payload.put("password",password);
            // ⽣成JWT的令牌
            String token = JwtUtils.createToken(payload);
            map.put("state",true);
            map.put("msg","认证成功");
            // 响应token
            map.put("token",token);

        }catch (Exception e){
            map.put("state",false);
            map.put("msg",e.getMessage());
        }
        return map;
    }

    @GetMapping("/fp_test")
    public String fp_test() {
        FpOtherInformation fpOtherInformation = fpOtherInformationService.getById(1);
        return fpOtherInformation.toString();
    }

}
